home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Is This Bad Coding Practice?
- Date: 31 Mar 1996 10:02:20 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4jmhbdINN71a@keats.ugrad.cs.ubc.ca>
- References: <4jgnt2$9d1@loki.tor.hookup.net> <828135115snz@genesis.demon.co.uk> <4jjqf1$6c1@loki.tor.hookup.net>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4jjqf1$6c1@loki.tor.hookup.net>,
- Rajendra Singh <Rajendra_Singh@msn.com> wrote:
- >Lawrence Kirby <fred@genesis.demon.co.uk> wrote:
- >
- >>No, as soon as func1 returns test doesn't exist any more so you cannot
- >>safely access it (doing so results in undefined behaviour). Don't
- >>do it, even if it seems to work on your system - it will bite you, sooner
- >>rather than later if you're lucky.
- >
- >I was working with a company and one of the senior programmers had
- >this piece of code in production. When I questioned him about it, he
- >says that it will always work. I had my doubts, that's why I was
- >curious as to whether or not it would always work.
-
- Of course it will always work! Once it is compiled on a particular machine,
- as part of a particular program, it will do its job until the end of time!
-
- >By the way, the forementioned piece of code worked on AIX, SCO, HPUX,
- >and OS/2.
-
- Because they all use stacks in similar ways.
-
- Suppose I modified the operating system such that when I pop the stack, it will
- actually free a page if the stack pointer increments past a page boundary
- (downward growing stack, obviously). That method will no longer work. Or what
- if the calling code simply uses the stack for temporary storage, or calls
- another function before trying to access the data? What if the stack of
- activation records is just a dynamically allocated linked list?
-
- **
- ** WHAT IF A SIGNAL HAPPENS and puts its own context info onto the stack of the
- ** process?
- **
-
- Many UNIX OS's put the signal context information onto the process' stack.
- Under Linux, I can modify the processor status bits from a signal handler,
- because they are put into a structure _on the stack_ --- precisely where a
- previous local variable used to live!
-
- That guy has no place as ``senior programmer''. Chances are he knows that it's
- wrong, but being the senior guy is not able to admit that he is wrong. Why not
- give us the e-mail address of this individual and his boss! A little
- disciplinary action is in order! :))
-
- I'm graduating from CompSci and need a high paying job ASAP. This could be it!
- Where do you live?
-
- I bet that the same programmer advocating this ad-hoc method will one day
- forget that a function he once wrote returns a pointer to a local variable, and
- will try to use that pointer after having called another function which
- clobbers the stack. Or maybe a signal handler will be called while he is using
- the illegal pointer! The result will be a defect that could cause all kinds of
- harm to profit, data, property, life, limb, user sanity... Oh boy, what a
- clueless moron of a senior programmer. (Is this government sector by any
- chance?)
-
- It is sheer irresponsibility for a professional to willingly introduce
- obviously undefined behavior into production code.
- --
-
-